package com.xpgk.mvc.ddc.maintenance.vehicleInformation;

import com.jfinal.log.Log;
import com.xpgk.annotation.Service;
import com.xpgk.constant.ConstantRender;
import com.xpgk.dto.RenderBean;
import com.xpgk.mvc.base.BaseService;

@Service(name = VehicleInformationService.serviceName)
public class VehicleInformationService extends BaseService{

	@SuppressWarnings("unused")
	private static final Log log = Log.getLog(VehicleInformationService.class);

	public static final String serviceName = "vehicleInformationService";
	
	/**
	 * 添加产品
	 * @param user
	 * @param organIds
	 * @return
	 */
	public RenderBean addVehicle(VehicleInformation vehicleInformation){
		RenderBean result = new RenderBean();
		String sql = getSqlMy(VehicleInformation.sqlId_selectByPlateNumber);
		VehicleInformation pm = VehicleInformation.dao.findFirst(sql,vehicleInformation.getStr(VehicleInformation.column_model));
		if(pm!=null){
			result.setCode(ConstantRender.render_error_code);
			result.setMsg("车牌型号重复！");
		}else{
			vehicleInformation.set(VehicleInformation.column_dataStatus, "1");
			if(!vehicleInformation.save()){
				result.setCode(ConstantRender.render_error_code);
				result.setMsg("保存失败！");
			}else{
				result.setCode(ConstantRender.render_success_code);
				result.setMsg("保存成功！");
			}
		}
		
		return result;
	}
	
	/**
	 * 编辑产品
	 * @param user
	 * @param organIds
	 * @return
	 */
	public RenderBean upVehicle(VehicleInformation vehicleInformation){
		RenderBean result = new RenderBean();
		String sql = getSqlMy(VehicleInformation.sqlId_selectByPlateNumber);
		VehicleInformation pm = VehicleInformation.dao.findFirst(sql,vehicleInformation.getStr(VehicleInformation.column_model));
		if(pm!=null){
			if(!pm.getPKValue().equals(vehicleInformation.getPKValue())){
				result.setCode(ConstantRender.render_error_code);
				result.setMsg("车牌型号重复！");
			}else{
				if(!vehicleInformation.update()){
					result.setCode(ConstantRender.render_error_code);
					result.setMsg("修改失败！");
				}else{
					result.setCode(ConstantRender.render_success_code);
					result.setMsg("修改成功！");
				}
			}
		}else{
			if(!vehicleInformation.update()){
				result.setCode(ConstantRender.render_error_code);
				result.setMsg("修改失败！");
			}else{
				result.setCode(ConstantRender.render_success_code);
				result.setMsg("修改成功！");
			}
		}
		
		
		return result;
	}

}
